package snapex.core.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static snapex.core.mapper.UserDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.User;

@Mapper
public interface UserMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<User> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("UserResult")
    User selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UserResult", value = {
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="open_id", property="openId", jdbcType=JdbcType.VARCHAR),
        @Result(column="passcode", property="passcode", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="nickname", property="nickname", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="email_address", property="emailAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile_number", property="mobileNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="locked", property="locked", jdbcType=JdbcType.CHAR),
        @Result(column="disabled", property="disabled", jdbcType=JdbcType.CHAR),
        @Result(column="credential_expired", property="credentialExpired", jdbcType=JdbcType.CHAR),
        @Result(column="create_timestamp", property="createTimestamp", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="wechat_key", property="wechatKey", jdbcType=JdbcType.VARCHAR)
    })
    List<User> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(user);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, user);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String username_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, user)
                .where(username, isEqualTo(username_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(User record) {
        return insert(SqlBuilder.insert(record)
                .into(user)
                .map(username).toProperty("username")
                .map(openId).toProperty("openId")
                .map(passcode).toProperty("passcode")
                .map(userId).toProperty("userId")
                .map(nickname).toProperty("nickname")
                .map(password).toProperty("password")
                .map(emailAddress).toProperty("emailAddress")
                .map(mobileNumber).toProperty("mobileNumber")
                .map(locked).toProperty("locked")
                .map(disabled).toProperty("disabled")
                .map(credentialExpired).toProperty("credentialExpired")
                .map(createTimestamp).toProperty("createTimestamp")
                .map(wechatKey).toProperty("wechatKey")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(User record) {
        return insert(SqlBuilder.insert(record)
                .into(user)
                .map(username).toPropertyWhenPresent("username", record::getUsername)
                .map(openId).toPropertyWhenPresent("openId", record::getOpenId)
                .map(passcode).toPropertyWhenPresent("passcode", record::getPasscode)
                .map(userId).toPropertyWhenPresent("userId", record::getUserId)
                .map(nickname).toPropertyWhenPresent("nickname", record::getNickname)
                .map(password).toPropertyWhenPresent("password", record::getPassword)
                .map(emailAddress).toPropertyWhenPresent("emailAddress", record::getEmailAddress)
                .map(mobileNumber).toPropertyWhenPresent("mobileNumber", record::getMobileNumber)
                .map(locked).toPropertyWhenPresent("locked", record::getLocked)
                .map(disabled).toPropertyWhenPresent("disabled", record::getDisabled)
                .map(credentialExpired).toPropertyWhenPresent("credentialExpired", record::getCredentialExpired)
                .map(createTimestamp).toPropertyWhenPresent("createTimestamp", record::getCreateTimestamp)
                .map(wechatKey).toPropertyWhenPresent("wechatKey", record::getWechatKey)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<User>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, username, openId, passcode, userId, nickname, password, emailAddress, mobileNumber, locked, disabled, credentialExpired, createTimestamp, wechatKey)
                .from(user);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<User>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, username, openId, passcode, userId, nickname, password, emailAddress, mobileNumber, locked, disabled, credentialExpired, createTimestamp, wechatKey)
                .from(user);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default User selectByPrimaryKey(String username_) {
        return SelectDSL.selectWithMapper(this::selectOne, username, openId, passcode, userId, nickname, password, emailAddress, mobileNumber, locked, disabled, credentialExpired, createTimestamp, wechatKey)
                .from(user)
                .where(username, isEqualTo(username_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(User record) {
        return UpdateDSL.updateWithMapper(this::update, user)
                .set(username).equalTo(record::getUsername)
                .set(openId).equalTo(record::getOpenId)
                .set(passcode).equalTo(record::getPasscode)
                .set(userId).equalTo(record::getUserId)
                .set(nickname).equalTo(record::getNickname)
                .set(password).equalTo(record::getPassword)
                .set(emailAddress).equalTo(record::getEmailAddress)
                .set(mobileNumber).equalTo(record::getMobileNumber)
                .set(locked).equalTo(record::getLocked)
                .set(disabled).equalTo(record::getDisabled)
                .set(credentialExpired).equalTo(record::getCredentialExpired)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(wechatKey).equalTo(record::getWechatKey);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(User record) {
        return UpdateDSL.updateWithMapper(this::update, user)
                .set(username).equalToWhenPresent(record::getUsername)
                .set(openId).equalToWhenPresent(record::getOpenId)
                .set(passcode).equalToWhenPresent(record::getPasscode)
                .set(userId).equalToWhenPresent(record::getUserId)
                .set(nickname).equalToWhenPresent(record::getNickname)
                .set(password).equalToWhenPresent(record::getPassword)
                .set(emailAddress).equalToWhenPresent(record::getEmailAddress)
                .set(mobileNumber).equalToWhenPresent(record::getMobileNumber)
                .set(locked).equalToWhenPresent(record::getLocked)
                .set(disabled).equalToWhenPresent(record::getDisabled)
                .set(credentialExpired).equalToWhenPresent(record::getCredentialExpired)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(wechatKey).equalToWhenPresent(record::getWechatKey);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(User record) {
        return UpdateDSL.updateWithMapper(this::update, user)
                .set(openId).equalTo(record::getOpenId)
                .set(passcode).equalTo(record::getPasscode)
                .set(userId).equalTo(record::getUserId)
                .set(nickname).equalTo(record::getNickname)
                .set(password).equalTo(record::getPassword)
                .set(emailAddress).equalTo(record::getEmailAddress)
                .set(mobileNumber).equalTo(record::getMobileNumber)
                .set(locked).equalTo(record::getLocked)
                .set(disabled).equalTo(record::getDisabled)
                .set(credentialExpired).equalTo(record::getCredentialExpired)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(wechatKey).equalTo(record::getWechatKey)
                .where(username, isEqualTo(record::getUsername))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(User record) {
        return UpdateDSL.updateWithMapper(this::update, user)
                .set(openId).equalToWhenPresent(record::getOpenId)
                .set(passcode).equalToWhenPresent(record::getPasscode)
                .set(userId).equalToWhenPresent(record::getUserId)
                .set(nickname).equalToWhenPresent(record::getNickname)
                .set(password).equalToWhenPresent(record::getPassword)
                .set(emailAddress).equalToWhenPresent(record::getEmailAddress)
                .set(mobileNumber).equalToWhenPresent(record::getMobileNumber)
                .set(locked).equalToWhenPresent(record::getLocked)
                .set(disabled).equalToWhenPresent(record::getDisabled)
                .set(credentialExpired).equalToWhenPresent(record::getCredentialExpired)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(wechatKey).equalToWhenPresent(record::getWechatKey)
                .where(username, isEqualTo(record::getUsername))
                .build()
                .execute();
    }
}